package com.ss.android.article.base.feature.user.account.view;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.bytedance.article.a.a.c;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.collection.WeakHandler;
import com.squareup.picasso.Picasso;
import com.ss.android.account.b.b;
import com.ss.android.account.e.MuteQuickClickListener;
import com.ss.android.account.model.ImageModel;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.user.account.model.AccountResult;
import com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter;
import com.ss.android.article.base.ui.InputUserInfoDialog;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.NightModeAsyncImageView;
import com.ss.android.common.dialog.AlertDialog;
import com.ss.android.common.util.NetworkUtils;

public final class a extends c<AccountEditPresenter> implements WeakHandler.Callback, com.ss.android.account.b.b.a, k {
    private TextView A;
    private TextView B;
    private ProgressBar C;
    private View D;
    private TextView E;
    private TextView F;
    private ProgressBar G;
    private View H;
    private b I;
    private WeakHandler J;
    private MuteQuickClickListener K;
    TextView b;
    TextView c;
    InputUserInfoDialog d;
    InputUserInfoDialog e;
    AccountResult f;
    private View g;
    private TextView h;
    private TextView i;
    private View j;
    private TextView k;
    private NightModeAsyncImageView l;
    private ProgressBar m;
    private View n;
    private View o;
    private TextView p;
    private ProgressBar q;
    private View r;
    private TextView s;
    private TextView t;
    private ProgressBar u;
    private View v;
    private TextView w;
    private TextView x;
    private ProgressBar y;
    private View z;

    public a() {
        this.J = new WeakHandler(((WeakHandler.Callback) this));
        this.f = new AccountResult();
        this.K = new com.ss.android.article.base.feature.user.account.view.b(this);
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter A(a arg1) {
        return arg1.mPresenter;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter B(a arg1) {
        return arg1.mPresenter;
    }

    static ProgressBar C(a arg1) {
        return arg1.C;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter D(a arg1) {
        return arg1.mPresenter;
    }

    public static void a(Context arg2, DialogInterface.OnClickListener arg3, DialogInterface.OnClickListener arg4) {
        if (arg2 != null) {
            AppData.getInstance();
            AlertDialog.Builder v0 = com.ss.android.j.b.createDialogBuilder(arg2);
            v0.setMessage(com.ss.android.article.browser.R.string.ar);
            v0.setNegativeButton(com.ss.android.article.browser.R.string.label_cancel, arg4);
            v0.setPositiveButton(com.ss.android.article.browser.R.string.aq, arg3);
            v0.show();
        }
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter a(a arg1) {
        return arg1.mPresenter;
    }

    public final int getLayoutResId() {
        return R.layout.a0;
    }

    @NonNull
    public final AccountEditPresenter createPresenter(Context context) {
        return new AccountEditPresenter(context);
    }

    public final void a(int arg5) {
        int v2 = View.GONE;
        int v1 = 0;
        TextView v3 = this.b;
        int v0 = arg5 == View.VISIBLE ? View.VISIBLE : v2;
        v3.setVisibility(v0);
        View v0_1 = this.H;
        if (arg5 != 0) {
            v1 = v2;
        }

        v0_1.setVisibility(v1);
    }

    public final void initView(View arg4) {
        if (this.I == null) {
            this.I = new b(this.getActivity(), ((Fragment) this), this.J, ((com.ss.android.account.b.b.a) this));
        }

        this.g = arg4.findViewById(com.ss.android.article.browser.R.id.g8);
        this.i = arg4.findViewById(com.ss.android.article.browser.R.id.back);
        this.b = arg4.findViewById(com.ss.android.article.browser.R.id.right_text);
        this.h = arg4.findViewById(com.ss.android.article.browser.R.id.title);
        this.j = arg4.findViewById(com.ss.android.article.browser.R.id.ga);
        arg4.findViewById(com.ss.android.article.browser.R.id.gb);
        this.k = arg4.findViewById(com.ss.android.article.browser.R.id.gc);
        this.l = arg4.findViewById(com.ss.android.article.browser.R.id.gd);
        this.m = arg4.findViewById(com.ss.android.article.browser.R.id.ge);
        this.n = arg4.findViewById(com.ss.android.article.browser.R.id.gf);
        arg4.findViewById(com.ss.android.article.browser.R.id.gi);
        this.o = arg4.findViewById(com.ss.android.article.browser.R.id.gk);
        arg4.findViewById(com.ss.android.article.browser.R.id.gl);
        this.p = arg4.findViewById(com.ss.android.article.browser.R.id.gm);
        this.c = arg4.findViewById(com.ss.android.article.browser.R.id.gn);
        this.q = arg4.findViewById(com.ss.android.article.browser.R.id.go);
        this.r = arg4.findViewById(com.ss.android.article.browser.R.id.gp);
        arg4.findViewById(com.ss.android.article.browser.R.id.gq);
        this.s = arg4.findViewById(com.ss.android.article.browser.R.id.gr);
        this.t = arg4.findViewById(com.ss.android.article.browser.R.id.gs);
        this.u = arg4.findViewById(com.ss.android.article.browser.R.id.gt);
        this.v = arg4.findViewById(com.ss.android.article.browser.R.id.gw);
        this.w = arg4.findViewById(com.ss.android.article.browser.R.id.gz);
        this.x = arg4.findViewById(com.ss.android.article.browser.R.id.gy);
        this.y = arg4.findViewById(com.ss.android.article.browser.R.id.h0);
        this.z = arg4.findViewById(com.ss.android.article.browser.R.id.h1);
        this.A = arg4.findViewById(com.ss.android.article.browser.R.id.h4);
        this.B = arg4.findViewById(com.ss.android.article.browser.R.id.h3);
        this.C = arg4.findViewById(com.ss.android.article.browser.R.id.h5);
        this.D = arg4.findViewById(com.ss.android.article.browser.R.id.h6);
        this.E = arg4.findViewById(com.ss.android.article.browser.R.id.h9);
        this.F = arg4.findViewById(com.ss.android.article.browser.R.id.h8);
        this.G = arg4.findViewById(com.ss.android.article.browser.R.id.h_);
        this.H = arg4.findViewById(com.ss.android.article.browser.R.id.hb);
    }

    public final void a(String arg7) {
        int v5 = R.color.ssxinzi5;
        int v4 = View.GONE;
        this.x.setVisibility(v4);
        if (arg7 != null) {
            arg7 = arg7.replaceAll("\n", "").trim();
            this.w.setTextColor(this.getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi1));
            if (arg7.equals("1")) {
                this.w.setText(com.ss.android.article.browser.R.string.ln);
                this.f.gender = 1;
            } else if (arg7.equals("2")) {
                this.w.setText(com.ss.android.article.browser.R.string.lm);
                this.f.gender = 2;
            } else {
                this.w.setTextColor(this.getResources().getColor(v5));
                this.w.setText(com.ss.android.article.browser.R.string.qn);
            }
        }

        this.v.setEnabled(true);
        int v0 = this.getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi3);
        this.getResources().getColor(com.ss.android.article.browser.R.color.cg);
        if ((android.support.design.a.isTextEmpty(arg7)) || ("0".equals(arg7))) {
            this.w.setTextColor(this.getResources().getColor(v5));
        } else {
            this.w.setTextColor(v0);
        }

        this.y.setVisibility(v4);
    }

    public final void a(boolean arg4) {
        this.b.setEnabled(arg4);
        int v1 = this.getResources().getColor(com.ss.android.article.browser.R.color.btn_common_text);
        int v0 = this.getResources().getColor(com.ss.android.article.browser.R.color.cg);
        TextView v2 = this.b;
        if (arg4) {
            v0 = v1;
        }

        v2.setTextColor(v0);
    }

    public final void a(boolean arg5, Uri uri, boolean arg7) {
        int v2 = View.GONE;
        TextView v3 = this.k;
        int v0 = arg5 ? View.VISIBLE : v2;
        v3.setVisibility(v0);
        if (uri != null) {
            if (uri.getScheme() == null || !uri.getScheme().startsWith("http")) {
                Picasso picasso = Picasso.with(this.getActivity());
                if (uri == null) {
                    throw new IllegalArgumentException("uri == null");
                } else {
                    picasso.cache.clearKeyUri(uri.toString());
                }
            }
            this.f.avatarUrl = uri.toString();
        }

        this.l.setImageURI(null);
        this.l.setImageURI(uri);
        this.j.setEnabled(arg7);
        NightModeAsyncImageView v3_1 = this.l;
        float v0_2 = !arg5 ? 1f : 0.5f;
        v3_1.setAlpha(v0_2);
        this.l.setVisibility(View.VISIBLE);
        this.m.setVisibility(v2);
    }

    public final void a(boolean arg4, String arg5, boolean arg6) {
        TextView v1 = this.p;
        int v0 = arg4 ? View.VISIBLE : View.GONE;
        v1.setVisibility(v0);
        this.c.setText(((CharSequence) arg5));
        this.o.setEnabled(arg6);
        this.f.userName = arg5;
        int v1_1 = this.getResources().getColor(com.ss.android.article.browser.R.color.cg);
        v0 = arg6 ? this.getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi3) : v1_1;
        TextView v2 = this.c;
        if (arg4) {
            v0 = v1_1;
        }

        v2.setTextColor(v0);
        this.q.setVisibility(View.INVISIBLE);
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter b(a arg1) {
        return arg1.mPresenter;
    }

    public final void b() {
    }

    public final void b(String arg6) {
        int v4 = R.color.ssxinzi5;
        int v3 = View.GONE;
        this.F.setVisibility(v3);
        if (!android.support.design.a.isTextEmpty(arg6)) {
            this.E.setTextColor(this.getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi1));
            arg6 = arg6.replaceAll("\n", "").trim().replaceAll(" +", " ");
            this.E.setText(((CharSequence) arg6));
            this.f.location = arg6;
        } else {
            this.E.setTextColor(this.getResources().getColor(v4));
            this.E.setText(com.ss.android.article.browser.R.string.qn);
        }

        this.D.setEnabled(true);
        int v0 = this.getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi3);
        this.getResources().getColor(com.ss.android.article.browser.R.color.cg);
        if (!android.support.design.a.isTextEmpty(arg6)) {
            this.E.setTextColor(v0);
        } else {
            this.E.setTextColor(this.getResources().getColor(v4));
        }

        this.G.setVisibility(v3);
    }

    public final void b(boolean arg5, String arg6, boolean arg7) {
        int v1 = View.GONE;
        TextView v2 = this.s;
        int v0 = arg5 ? View.VISIBLE : v1;
        v2.setVisibility(v0);
        if (arg6 != null) {
            String v0_1 = arg6.replaceAll("\n", "").trim().replaceAll(" +", " ");
            this.t.setText(((CharSequence) v0_1));
            this.f.description = v0_1;
        }

        this.r.setEnabled(arg7);
        int v2_1 = this.getResources().getColor(com.ss.android.article.browser.R.color.cg);
        v0 = arg7 ? this.getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi3) : v2_1;
        TextView v3 = this.t;
        if (arg5) {
            v0 = v2_1;
        }

        v3.setTextColor(v0);
        this.u.setVisibility(v1);
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter c(a arg1) {
        return arg1.mPresenter;
    }

    public final void c() {
        this.h.setText(com.ss.android.article.browser.R.string.account_edit_profile);
        this.b.setText(com.ss.android.article.browser.R.string.aq);
        this.j.setEnabled(false);
        this.o.setEnabled(false);
        this.r.setEnabled(false);
        this.v.setEnabled(false);
        this.z.setEnabled(false);
        this.D.setEnabled(false);
        this.a(false);
    }

    public final void c(String arg9) {
        int v7 = R.color.ssxinzi5;
        int v6 = View.GONE;
        this.B.setVisibility(v6);
        if (!android.support.design.a.isTextEmpty(arg9)) {
            this.A.setTextColor(this.getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi1));
            arg9 = arg9.replaceAll("\n", "").trim().replaceAll(" +", " ");
            TextView v1 = this.A;
            String v0 = !android.support.design.a.q(arg9) ? "" : android.support.design.a.a(arg9, 1) + "-" + (android.support.design.a.a(arg9, 2) + 1) + "-" + android.support.design.a.a(arg9, 5);
            v1.setText(((CharSequence) v0));
            this.f.birthday = arg9;
        } else {
            this.A.setTextColor(this.getResources().getColor(v7));
            this.A.setText(com.ss.android.article.browser.R.string.qn);
        }

        this.z.setEnabled(true);
        int v0_1 = this.getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi3);
        this.getResources().getColor(com.ss.android.article.browser.R.color.cg);
        if (!android.support.design.a.isTextEmpty(arg9)) {
            this.A.setTextColor(v0_1);
        } else {
            this.A.setTextColor(this.getResources().getColor(v7));
        }

        this.C.setVisibility(v6);
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter d(a arg1) {
        return arg1.mPresenter;
    }

    public final void d() {
        this.i.setOnClickListener(this.K);
        this.b.setOnClickListener(this.K);
        this.j.setOnClickListener(this.K);
        this.n.setOnClickListener(this.K);
        this.o.setOnClickListener(this.K);
        this.r.setOnClickListener(this.K);
        this.g.setOnClickListener(this.K);
        this.v.setOnClickListener(this.K);
        this.z.setOnClickListener(this.K);
        this.D.setOnClickListener(this.K);
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter e(a arg1) {
        return arg1.mPresenter;
    }

    static InputUserInfoDialog f(a arg1) {
        return arg1.e;
    }

    public final b f() {
        if (this.I == null) {
            this.I = new b(this.getActivity(), ((Fragment) this), this.J, ((com.ss.android.account.b.b.a) this));
        }

        return this.I;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter g(a arg1) {
        return arg1.mPresenter;
    }

    public final boolean g() {
        boolean v0;
        int v1 = View.GONE;
        if (!NetworkUtils.isNetworkAvailable(this.getContext())) {
            this.q.setVisibility(v1);
            this.u.setVisibility(v1);
            this.y.setVisibility(v1);
            this.G.setVisibility(v1);
            this.C.setVisibility(v1);
            android.support.design.a.showImageToast(this.getContext(), R.string.ss_error_no_connections, R.drawable.close_popup_textpage);
            v0 = false;
        } else {
            v0 = true;
        }

        return v0;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter h(a arg1) {
        return arg1.mPresenter;
    }

    public final void handleMsg(Message message) {
        int v5 = View.GONE;
        if (this.isViewValid()) {
            switch (message.what) {
                case 1023: {
                    if ((message.obj instanceof ImageModel)) {
                        Object v0 = message.obj;
                        AccountEditPresenter v1 = this.mPresenter;
                        ((AccountEditPresenter) v1).i = ((ImageModel) v0).getUriStr();
                        if (v1.hasView()) {
                            v1.mView.a(true);
                        }

                        int v1_1 = this.mPresenter.f;
                        if (v1_1 == 0) {
                            this.m.setVisibility(v5);
                            this.l.setVisibility(View.VISIBLE);
                            this.a(false, ((ImageModel) v0).getLocalUri(), true);
                            this.a(true);
                        } else if (v1_1 != 2 && v1_1 != 1) {
                        } else {
                            this.mPresenter.f();
                        }
                    }

                }
                case 1024: {
                    this.m.setVisibility(v5);
                    this.l.setVisibility(View.VISIBLE);
                    UIUtils.showImageToast(this.getActivity(), R.drawable.close_popup_textpage, R.string.account_avatar_upload_error);
                    return;
                }
            }

            return;


        }
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter i(a arg1) {
        return arg1.mPresenter;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter j(a arg1) {
        return arg1.mPresenter;
    }

    static ProgressBar k(a arg1) {
        return arg1.q;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter l(a arg1) {
        return arg1.mPresenter;
    }

    static InputUserInfoDialog m(a arg1) {
        return arg1.d;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter n(a arg1) {
        return arg1.mPresenter;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter o(a arg1) {
        return arg1.mPresenter;
    }

    public final void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        this.I.a(requestCode, resultCode, data);
        if (requestCode == 110 && resultCode == -1 && data != null) {
            this.mPresenter.n = data.getParcelableExtra("location");
            this.G.setVisibility(View.VISIBLE);
            this.mPresenter.g();
        }
    }

    public final void onDestroyView() {
        InputUserInfoDialog v1 = null;
        super.onDestroyView();
        if (this.d != null) {
            this.d.c();
            this.d = v1;
        }

        if (this.e != null) {
            this.e.c();
            this.e = v1;
        }
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter p(a arg1) {
        return arg1.mPresenter;
    }

    public final void p_() {
        if (this.isViewValid()) {
            this.m.setVisibility(View.VISIBLE);
            this.l.setVisibility(View.GONE);
        }
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter q(a arg1) {
        return arg1.mPresenter;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter r(a arg1) {
        return arg1.mPresenter;
    }

    static ProgressBar s(a arg1) {
        return arg1.u;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter t(a arg1) {
        return arg1.mPresenter;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter u(a arg1) {
        return arg1.mPresenter;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter v(a arg1) {
        return arg1.mPresenter;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter w(a arg1) {
        return arg1.mPresenter;
    }

    static AccountResult x(a arg1) {
        return arg1.f;
    }

    static com.ss.android.article.base.feature.user.account.presenter.AccountEditPresenter y(a arg1) {
        return arg1.mPresenter;
    }

    static ProgressBar z(a arg1) {
        return arg1.y;
    }
}

